/*
 * @descripttion: 封装axios
 * @author: cp
 * @Date: 2021-04-25 10:20:21
 */


import axios from 'axios'

axios.defaults.baseURL = process.env.NODE_ENV === 'development' ? 'http://localhost:7588/api' : '2'

const service = axios.create({
  timeout: 20000,
})

// 请求头
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    return Promise.reject(error)
  }
)



// 响应体
service.interceptors.response.use(
  response => {
    const res = response.data
    console.log(res)
    if (res.errno === 0) {
      return res.data
    }
    if (res.errno === 1) {
      alert(res.message)
    }
  }
)

export default service